<template>
    <div class="img-modal">
        <img :src="imgUrl" :alt="imgAlt" :width="imgWidth" :height="imgHeight" @click="isModalVisible = true">

        <div v-if="isModalVisible" class="modal" @click.self="isModalVisible = false">
            <img :src="imgUrl" class="modal-image">
        </div>
    </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue';

const props = defineProps({
    imgUrl: {
        type: String,
        required: true
    },
    imgAlt: {
        type: String,
        default: ''
    },
    imgWidth: {
        type: String,
        default: 'auto'
    },
    imgHeight: {
        type: String,
        default: 'auto'
    }
})

const isModalVisible = ref(false);
</script>

<style scoped>
.modal {
    display: flex;
    justify-content: center;
    align-items: center;
    position: fixed;
    z-index: 9999;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
}

.modal-image {
    max-width: 90%;
    max-height: 90%;
}
</style>